<extend name="./Application/Home/View/Layouts/application.html"/>

<block name="content">

    <div class="clearsH"></div>

    <div class="all">
        <ul class="menu">
            <li><a href="javascript:void(0);">全部商品</a></li>
            <li><a href="javascript:void(0);" id="list"><i class="fa fa-th"></i></a></li>
        </ul>
    </div>

    <div class="products">

        <volist name="products" id="product">
            <dl>
                <dt><a href="{{:U('Index/show',['id'=>$product[id]])}}">
                    <img class="img-responsive" src="{{$product.thumb}}" alt="商品图片" style="width: 152px;height: 92px;"/></a>
                </dt>
                <dd><a href="{{:U('Index/show',['id'=>$product[id]])}}">{{$product.name}}</a><span>已售 12</span></dd>
                <dd>库存 {{$product.stock}}</dd>
                <dd>¥ {{$product.price}}元</dd>
            </dl>
        </volist>

        <div class="clears"></div>
    </div>
    <div class="perspective">
        <span class="more">查看更多</span>
    </div>

</block>
<block name="js">
    <script>
        var nStart = 2;
        $(function () {
            $('.more').click(function () {
                var _this = $(".products");
                if (nStart >= '{{$total}}') {
                    alert('后面没有数据了！');
                    _this.text('后面没有数据了');
                    return false;
                } else {
                    $.post("{{:U('ajax_index')}}", {start: nStart}, function (res) {
                        $.each(res['result'], function (i, item) {
                           var html = '<dl>' +
                               '<dt><a href="/Home/Index/show/id/'+item.id+'">' +
                               '<img class="img-responsive" src="'+item.thumb+'" alt="商品图片" style="width: 152px;height: 92px;"/></a>' +
                               '</dt>' +
                               '<dd><a href="/Home/Index/show/id/'+item.id+'">'+item.name+'</a><span>已售 '+item.sale_done+'</span></dd>' +
                               '<dd>库存 '+item.stock+'</dd>' +
                               '<dd>¥ '+item.price+'元</dd>' +
                               '</dl>';

                           _this.append(html);
                        });
                    });
                    nStart += 2;
                }
            });
        });
    </script>

</block>
